package com.wjm.blog.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wjm.blog.common.base.response.Result;
import com.wjm.blog.common.exception.BizException;
import com.wjm.blog.system.entity.SysUserEntity;
import com.wjm.blog.system.mapper.SysUserMapper;
import com.wjm.blog.system.service.IAuthService;
import com.wjm.blog.system.vo.request.SysUserQueryVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author BUG WRITTER
 * @date 2023/10/18 15:08
 */
@Log4j2
@Service
public class AuthServiceImpl implements IAuthService {

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 登录
     *
     * @param userQueryVo
     * @return
     * @throws Exception
     */
    @Override
    public Result login(SysUserQueryVo userQueryVo) throws Exception {

        SysUserEntity sysUserEntity = userMapper.selectOne(new LambdaQueryWrapper<SysUserEntity>()
                .eq(SysUserEntity::getUserAccount, userQueryVo.getUserAccount())
                .eq(SysUserEntity::getUserPwd, userQueryVo.getUserPwd()).last(" limit 1"));

        if (sysUserEntity == null) {
            throw new BizException("查无此人");
        }

        return Result.success(sysUserEntity);
    }
}
